import time
import threading
import queue
import datetime
import pandas as pd
import os
__path="E:\\testfile\\"
__listdir = os.listdir(__path)

class Worker(threading.Thread):
    def __init__(self, name, queue):
        threading.Thread.__init__(self)
        self.queue = queue
        self.start()    #执行run()

    def run(self):
        #循环，保证接着跑下一个任务
        while True:
            # 队列为空则退出线程
            if self.queue.empty():
                break
            # 获取一个队列数据
            foo = self.queue.get()
            # 延时1S模拟你要做的事情
            # time.sleep(1)
            __path = "E:\\testfile\\"
            df =pd.read_table(__path+foo,encoding="gbk")
            print(df.shape[0])
            # 打印
            print(self.getName() + " process " + str(foo))
            # 任务完成
            self.queue.task_done()

starttime = datetime.datetime.now()
# 队列
queue = queue.Queue()
# 加入100个任务队列


sum =0
for i in __listdir:
    queue.put(i)
    sum+=1
# 开10个线程
for i in range(1000):
    threadName = 'Thread' + str(i)
    Worker(threadName, queue)
# 所有线程执行完毕后关闭
queue.join()

endtime = datetime.datetime.now()
print('程序运行时间:' + str(endtime - starttime),sum)